var QueryShopController = function() {
  var userId = "";
  this.confirmShop = function(succFun) {
    var self = this;
    common.confirm({
      btnLeft: "新增门店",
      btnRight: "获取口碑门店",
      title: "",
      content: "<center>暂无门店</center>",
      callbackLeft: function() {
        AppUtil.call(AppUtil.APIS.PUSH_WINDOW, {
          url: "vuepages/index.html#/storeManage/editStore",
          suffixParams: "oldh5=T",
          target: "local",
          param: {
            title: null
          }
        });
      },
      callbackRight: function() {
        AppUtil.call(AppUtil.APIS.OPEN_AUTHV2, {}, function(result) {
          if (result != null && result.success && result.resultObject != null) {
            userId = result.resultObject;
          }
        });
        self.confirmAliOauthResult(succFun);
      }
    });
  };
  this.indexAliOauthCallBack = function(aliId, succFun) {
    if (aliId == null || aliId == undefined) {
      log4JS.info("indexAliOauthCallBack failed.aliId is " + aliId);
      return false;
    }
    var self = this;
    var serverUrl =
      App.serverUrl + "merchantApp/index/queryKbShop.do?aliId=" + aliId;
    var sucFunc = function(result) {
      if (String(result.success) == "true") {
        if (succFun) {
          succFun();
        } else {
          indexController.initUser();
        }
        log4JS.info("queryKbShop is success");
      } else {
        if (result.code == "-1") {
          DialogUtil.dialogWarn(
            "拉取失败，未订购过纵横客相关产品或未创建口碑门店!"
          );
        } else if (result.code == "-2") {
          DialogUtil.dialogWarn("已绑定口碑商户!");
        } else if (result.code == "-3") {
          DialogUtil.dialogWarn("关联失败，该商户已与" + result.msg + "关联");
        } else if (result.code == "-4") {
          DialogUtil.dialogWarn("此商户未订购纵横客的服务!");
        }
      }
    };

    var failFunc = function() {
      log4JS.info("queryKbShop failed. http status not 200");
      DialogUtil.dialogWarn("拉取口碑门店失败！");
    };
    CommonUtil.sendJsonpRequest({
      url: serverUrl,
      success: sucFunc,
      error: failFunc
    });
  };

  this.confirmAliOauthResult = function(succFun) {
    var self = this;

    common.confirm({
      btnLeft: "取消",
      btnRight: "授权成功",
      title: "",
      content: "<center>是否授权成功</center>",
      callbackLeft: function() {},
      callbackRight: function() {
        if (userId != "") {
          self.indexAliOauthCallBack(userId, succFun);
        } else {
          DialogUtil.dialogWarn("授权失败！");
        }
      }
    });
  };
};
